package com.cslg.questionnaires.service;

import com.cslg.questionnaires.entity.Question;
import com.cslg.questionnaires.mapper.QuestionMapper;
import com.cslg.questionnaires.utils.ServiceMessageBuilder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Service
public class TeacherAuditFormService {
    @Resource
    QuestionMapper questionMapper;

    public HashMap<String,Object> getUnAuditForm(){
        List<Question> unAuditquestions = questionMapper.getUnAuditQuestion();
        if (unAuditquestions.size() == 0){
            return ServiceMessageBuilder
                    .buildMessage(404,"没有需要审核的表单！",null);
        }else {
            return ServiceMessageBuilder
                    .buildMessage(200,"success",unAuditquestions);
        }
    }

    public HashMap<String,Object> passAuditByQuestionId(int questionId){
        int row = questionMapper.passAuditByQuestionId(questionId);
        if (row == 1){
            return ServiceMessageBuilder
                    .buildMessage(200,"success",null);
        }else {
            return ServiceMessageBuilder
                    .buildMessage(501,"error",null);
        }
    }

    public HashMap<String,Object> rejectAuditByQuestionId(int questionId){
        int row = questionMapper.rejectAuditByQuestionId(questionId);
        if (row == 1){
            return ServiceMessageBuilder
                    .buildMessage(200,"success",null);
        } else {
            return ServiceMessageBuilder
                    .buildMessage(501,"error",null);
        }
    }

}
